package com.zcl.网络;

import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/6/23  17:13
 */
public class SocketTest {

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("time-a.nist.gov", 13);
            socket.setSoTimeout(20000);

//            Socket socket1 = new Socket("time-a.nist.gov", 20000);

            Scanner scanner = new Scanner(socket.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                System.out.println(line);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
